package com.itheima.day11.myOtherio.test1;

import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 对象序列化流
         method1();

        // 对象反序列化流
         method2();

        // InvalidClassException
        // serialVersionUID = 2058945356941581400
        // serialVersionUID = 1073368056668472024

    }

    // 对象序列化流
    public static void method1() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("myCode\\src\\com\\itheima\\day11\\g.txt"));
        User u = new User();
        u.setUsername("aidmi123");
        u.setPassword("1577724623");
        oos.writeObject(u);
        oos.close();
    }

    // 对象反序列化流
    public static void method2() throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("myCode\\src\\com\\itheima\\day11\\g.txt"));
        User u = (User) ois.readObject();
        System.out.println(u);
        ois.close();
    }

}
